

class GMLoginUser {
  String nick;
  String icon;
  String ids;
  String sex;
  String city;
  String job;
  String sign;
  String birthday;
  int? coins;
  int level;

  GMLoginUser(
      {required this.nick,
      required this.icon,
      required this.ids,
      required this.sex,
      required this.city,
      required this.job,
      required this.sign,
      this.coins=0,
      this.level=0,
      required this.birthday});

  // 将用户信息转换成Map
  Map<String, dynamic> toJson() => {
        'nick': nick,
        'icon': icon,
        'ids': ids,
        'sex': sex,
        'city': city,
        'coins':coins,
        'job': job,
        'sign': sign,
        'birthday': birthday,
        'level':level
      };

  // 从Map转换回User对象
  factory GMLoginUser.fromJson(Map<String, dynamic> json) => GMLoginUser (
        nick: json['nick'],
        icon: json['icon'],
        ids: json['ids'],
        sex: json['sex'],
        coins: json['coins'],
        city: json['city'],
        job: json['job'],
        birthday: json['birthday'],
        sign: json['sign'],
        level: json['level']
      );
}

// class UserManager {
//   static final UserManager _instance = UserManager._internal();
//   factory UserManager() => _instance;
//   UserManager._internal();

//   GMLoginUser? _user;

//   GMLoginUser? get user => _user;

//   // 判断用户是否登录
//   bool get isLoggedIn => _user != null;

//   // 保存用户信息到本地
//   Future<void> saveUser(GMLoginUser user) async {
//     final SharedPreferences prefs = await SharedPreferences.getInstance();
//     String userString = json.encode(user.toJson());
//     await prefs.setString('user', userString);
//     _user = user;
//   }

//   // 从本地获取用户信息
//   Future<void> loadUser() async {
//     final SharedPreferences prefs = await SharedPreferences.getInstance();
//     String? userString = prefs.getString('user');
//     if (userString != null) {
//       _user = GMLoginUser.fromJson(json.decode(userString));
//     }
//   }

//   // 注销用户
//   Future<void> logout() async {
//     final SharedPreferences prefs = await SharedPreferences.getInstance();
//     await prefs.remove('user');
//     _user = null;
//   }
// }
